%% Element Distances
%   Calculates the distances of the elements that make of the axon model.
%   The axon is made up of the following element: NoR, MYSA, FLUT, STIN
%   - NoR = node of Ranvier
%   - MYSA and FLUT = paranodal segments
%   - STIN = internodal segments 
%   Elements are assembled in the following manner:
%   NoR-MYSA-FLUT-STIN-...-STIN-FLUT-MYSA-...repeat...NoR
%   (in MRG code, there are 6 STINs)
%   (in my modified version of the MRG code, there are 3 STINs)

clear all;
clc;

%% Geometrical Parameters
%   Calculate the geometry of elements based on fiber diameter, D.
%   - INL = internodal distance (from NoR to NoR)
%   - assume INL=100*D
%   - The relationship between INL and D is not linear (see McIntyre et
%   al., 2002) -- or more specifically, the works by Berthold, Nilsson, and
%   Rydmark mentioned in the McIntyre et al. work (2002).

D=2.5; % fiber diameter (um)
INL=200+(1600-200)*(D-2)/(16-2); % linear interpolation
% (INL of 200 and 1600 at D of 2 and 16, respectively.)

% number of elements
nonode=1; % NoR
nomysa=2; % MYSA
noflut=2; % FLUT
nostin=3; % STIN

% length of elements (um)
Lnode=1; % set value (based on Rydmark studies -- see above)
Lmysa=3; % set value (based on Berthold studies -- see above)
Lflut=10+(60-10)*(D-2)/(16-2); % linear interpolation
Lstin=(INL-Lnode-(nomysa*Lmysa)-(noflut*Lflut))/nostin; % based on above

%% Calculate Displacements
%   first NoR starts at 0
%   arc[...] denotes an arc length, as axon does not need to have a
%   straight trajectory

arc1=0; % middle of 1st NoR (centered at 0)
arc2=Lnode/2+Lmysa/2; % 0 to middle of 1st MYSA
arc3=Lnode/2+Lmysa+Lflut/2; % 0 to middle of 1st FLUT
arc4=Lnode/2+Lmysa+Lflut+Lstin/2; % 0 to middle of 1st STN
arc5=Lnode/2+Lmysa+Lflut+1.5*Lstin; % "" 2nd STIN
arc6=Lnode/2+Lmysa+Lflut+2.5*Lstin; % "" 3rd STIN
arc7=Lnode/2+Lmysa+1.5*Lflut+3*Lstin; % 0 to middle of 2nd FLUT
arc8=Lnode/2+1.5*Lmysa+2*Lflut+3*Lstin; % 0 to middle of 2nd MYSA
arc9=Lnode+2*Lmysa+2*Lflut+3*Lstin; % 0 to middle of next NoR
axon_arc=round([arc1,arc2,arc3,arc4,arc5,arc6,arc7,arc8,arc9]); % all the above

%% Write File
%   uncomment to write file

% filename = ['axonarc_',num2str(D),'um.txt'];
% dlmwrite(filename,axon_arc);
